package com.example.demo.netty.heart;

import org.springframework.util.CollectionUtils;

import java.util.LinkedList;
import java.util.concurrent.TimeUnit;

public class MyQueue {

    public volatile static LinkedList<String> queue = new LinkedList<>();

    public static String pollWhile() {
        while (CollectionUtils.isEmpty(queue)) {
            try {
                TimeUnit.MILLISECONDS.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return queue.poll();
    }

    public static String poll() {
        return queue.poll();
    }

    public static void offer(String ele) {
        queue.offer(ele);
    }
}
